#ifndef POSITIONMANAGER_H
#define POSITIONMANAGER_H

#include "position.h"
#include <QJsonObject>
#include <QString>
#include <QMap>
#include <Windows.h>

class PositionManager
{
public:
    PositionManager();

    int init();

    void createPosition(const QString& name);
    void savePositionsToFile(const QString& filename);
    bool trackRolePosition();
    Position* trackRolePositionAndReturn();
    void teleportRole();
    bool loadPos();

    bool isRoleClimbOrStop();
    Position* trackRoleVelocityAndReturn();

    double getX();
    double getY();
    double getZ();
    void deletePosition(const int idx);
    void sortUpPosition(const int idx);
    void usePosition(const int idx);
    QList<QJsonObject> getPositions() const;

    int resetDrake();
    bool pauseDrake();
    int speedUpDrake();
    int speedDownDrake();
    int resetSpeedDrake();

    float getFps();
    void setFps(float newFps);


private:
    QList<QJsonObject> positions;

    HANDLE game_process;
    uintptr_t base_address;

    uintptr_t xCoord;   // x坐标 内存位置
    uintptr_t yCoord;
    uintptr_t zCoord;
    uintptr_t xVelocityCoord;   // x方向的速度 内存位置
    uintptr_t yVelocityCoord;
    uintptr_t zVelocityCoord;
    double x;
    double y;
    double z;
    double xV;
    double yV;
    double zV;

    uintptr_t drakeDistSplineCoord; // 龙的初始化标记 内存地址
    uintptr_t drakeMouvementCoord;  // 龙的移速 内存地址
    float drakeDistSpline;  // 龙的初始化标记
    float drakeMouvement;   // 龙的移速
    bool DragonInited = false;

    uintptr_t fpsCoord;
    float fps;


    uintptr_t GetModuleBaseAddress(DWORD procId, const wchar_t* modName);

    int initPosMemoryAddress();
    int initVelocityMemoryAddress();
    int initDrakeMemoryAddress();
    int initFpsMemoryAddress();

    bool loadPositionsFromFile(const QString& filename);
    bool initDrakeMemoryAddressIfNot();

};

#endif // POSITIONMANAGER_H
